package org.seven.jrdp.commons.spring.mvc.converter;

import java.util.Date;

import org.apache.commons.lang3.time.DateUtils;
import org.seven.jrdp.commons.constant.GlobalContants;
import org.springframework.core.convert.converter.Converter;

public class DateConverter implements Converter<String, Date> {
	public Date convert(String source) {
		if (source == null || "".equals(source)) {
			return null;
		}
		try {
			return DateUtils.parseDate(source, GlobalContants.PATTERN_DATE, GlobalContants.PATTERN_DATETIME);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}